﻿#pragma execution_character_set("utf-8")
#ifndef DEVICEMANAGER_H
#define DEVICEMANAGER_H

#include <QJsonObject>
#include <QObject>
#include <QList>
#include <QThread>

#include "DeviceFactory/BaseDeviceFactory.h"
#include "BaseDevice.h"
#include "BaseManager.h"
#include "DeviceStatusList.h"

class DeviceManager:public BaseManager
{
    Q_OBJECT

private:
    DeviceManager();
    ~DeviceManager();
    DeviceManager(const DeviceManager&)=delete;
    DeviceManager& operator=(const DeviceManager&)=delete;

public:
    static DeviceManager& Instance();

    BaseDevice* GetDevice(QString name);

    QList<BaseDevice*> GetDevices(QJsonArray names);


    QList<QString> GetAllDeviceName();

    void SetWatch(bool isWatch);

    void Stop();
    void Reset();
    //QThread
    void run();

    void WaitForEnd();

signals:
    void UpdateStatus(DeviceStatusList items);

private:
    bool _isWatch=false;
    bool _isBreak=false;

    QList<BaseDevice*> _allDevices;
    QTimer* _watchTimer=nullptr;

    // BaseManager interface
public:
    virtual void SetFactory() override;

    virtual void Init() override;
};

#endif // DEVICEFACTORY_H
